package cn.hdax.test1;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

public class PutTable {

    static void put() throws IOException {
        //获取hbase的连接信息,默认情况下hbase-size.xml
        Configuration configuration = HBaseConfiguration.create() ;
        //得到hbase的连接信息
        Connection conn = ConnectionFactory.createConnection(configuration);
        //得到一张表
        Table tb=conn.getTable(TableName.valueOf("student"));
        Put p=new Put(Bytes.toBytes("s001"));
        p.addColumn(Bytes.toBytes("info"),Bytes.toBytes("name"),Bytes.toBytes("tongyao"));
        tb.put(p);
        Put p1=new Put(Bytes.toBytes("s002"));
        p1.addColumn(Bytes.toBytes("info"),Bytes.toBytes("name"),Bytes.toBytes("pengfei"));
        tb.put(p1);
        conn.close();
        System.out.println("put success!");
    }


    public static void main(String[] args) throws IOException {
        put() ;
    }


}
